'''
Created on 05/04/2013

@author: tsantana
'''

import thilux_pages
import thilux_session
from thilux_models import User, Role, Permission

page_by_role={
                'AppAdmin':(thilux_pages._page_reference.keys()),
                'Manager':(
                           'INDEX_PAGE',
                           'DOOR1',
                           'ADD_EMPLOYEE_PAGE',
                           ),
                'BasicEmployee':(
                                 'INDEX_PAGE',
                                 'DOOR1',),
                'SalesPerson':(
                               'INDEX_PAGE',
                               'DOOR1',)
              }

def encrypt(decrypted):
    
    if not isinstance(decrypted, str):
        raise TypeError('The decrypted message should be a string')
    result=''
    support_v=''
    
    for char in decrypted:
        
        str_char=str(ord(char))
        result +=str_char
        
    for c in result:
        support_v += chr(int(c))
        
    result = support_v
        
    return result

def can_access(page):
    
    role=thilux_session.get_user_role()
    
    if role:
        permission=role.permission
        
        if page in page_by_role[permission.name]:
            return True
        else:
            return False
    else:
        return False
        
    